// vim:ft=javascript

ARG_ENABLE("intl", "Enable internationalization support", "no");

if (PHP_INTL != "no") {
	if (CHECK_LIB("icudt.lib", "intl", PHP_INTL) &&
		CHECK_LIB("icuin.lib", "intl", PHP_INTL) &&
		CHECK_LIB("icuio.lib", "intl", PHP_INTL) &&
		CHECK_LIB("icuuc.lib", "intl", PHP_INTL) &&
					CHECK_HEADER_ADD_INCLUDE("unicode/utf.h", "CFLAGS_INTL")) {
		// always build as shared - zend_strtod.c/ICU type conflict
		EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", true,
								"/I \"" + configure_module_dirname + "\" /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
		ADD_EXTENSION_DEP('intl', 'date');
		ADD_SOURCES(configure_module_dirname + "/collator", "\
				collator_attr.cpp \
				collator_class.cpp \
				collator_compare.cpp \
				collator_convert.cpp \
				collator_create.cpp \
				collator_error.cpp \
				collator_is_numeric.cpp \
				collator_locale.cpp \
				collator_sort.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/common", "\
				common_error.cpp \
				common_enum.cpp \
				common_date.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/converter", "\
				converter.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/formatter", "\
				formatter_attr.cpp \
				formatter_class.cpp \
				formatter_data.cpp \
				formatter_format.cpp \
				formatter_main.cpp \
				formatter_parse.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/listformatter", "\
				listformatter_class.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/locale", "\
				locale.cpp \
				locale_class.cpp \
				locale_methods.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/msgformat", "\
				msgformat.cpp \
				msgformat_attr.cpp \
				msgformat_class.cpp \
				msgformat_data.cpp \
				msgformat_format.cpp \
				msgformat_helpers.cpp \
				msgformat_parse.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/grapheme", "\
                                grapheme_string.cpp grapheme_util.cpp  \
                                ", "intl");
		ADD_SOURCES(configure_module_dirname + "/normalizer", "\
				normalizer_class.cpp \
				normalizer_normalize.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/rangeformatter", "\
				rangeformatter_class.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/dateformat", "\
				dateformat.cpp \
				dateformat_class.cpp \
				dateformat_attr.cpp \
				dateformat_format.cpp \
				dateformat_format_object.cpp \
				dateformat_parse.cpp \
				dateformat_data.cpp \
				dateformat_attrcpp.cpp \
				dateformat_helpers.cpp \
				dateformat_create.cpp \
				datepatterngenerator_class.cpp \
				datepatterngenerator_methods.cpp \
				", "intl");
		ADD_SOURCES(configure_module_dirname + "/uchar", "\
				uchar.cpp",
				"intl");
		ADD_SOURCES(configure_module_dirname + "/idn", "\
				idn.cpp",
				"intl");
		ADD_SOURCES(configure_module_dirname + "/resourcebundle", "\
				resourcebundle.cpp \
				resourcebundle_class.cpp \
				resourcebundle_iterator.cpp",
				"intl");

		if (CHECK_HEADER_ADD_INCLUDE("unicode/uspoof.h", "CFLAGS_INTL")) {
			ADD_SOURCES(configure_module_dirname + "/spoofchecker", "\
					spoofchecker_class.cpp \
					spoofchecker_create.cpp \
					spoofchecker_main.cpp",
					"intl");
		}

		ADD_SOURCES(configure_module_dirname + "/transliterator", "\
				transliterator_class.cpp \
				transliterator_methods.cpp",
				"intl");

		ADD_SOURCES(configure_module_dirname + "/timezone", "\
				timezone_class.cpp \
				timezone_methods.cpp",
				"intl");

		ADD_SOURCES(configure_module_dirname + "/calendar", "\
				calendar_methods.cpp \
				gregoriancalendar_methods.cpp \
				calendar_class.cpp",
				"intl");

		ADD_SOURCES(configure_module_dirname + "/breakiterator", "\
				breakiterator_class.cpp \
				breakiterator_methods.cpp \
				breakiterator_iterators.cpp \
				rulebasedbreakiterator_methods.cpp \
				codepointiterator_internal.cpp \
				codepointiterator_methods.cpp ",
				"intl");

		/* Compat for ICU before 58.1.*/
		CHECK_LIB("icule.lib", "intl", PHP_INTL);
		CHECK_LIB("iculx.lib", "intl", PHP_INTL);
		ADD_FLAG("CFLAGS_INTL", "/std:c++17 /EHsc /DUNISTR_FROM_CHAR_EXPLICIT=explicit /DUNISTR_FROM_STRING_EXPLICIT=explicit /DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 /DU_HIDE_OBSOLETE_UTF_OLD_H=1");
	} else {
		WARNING("intl not enabled; libraries and/or headers not found");
	}
}
